<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
              width: 100px;
              height: 100px;
              margin: 20px;
        }

  </style>
</head>
<body>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
</body>
</html>
<script>
    var box =document.querySelectorAll(".box")
    var promise_box1 =new Promise(function(resolve,reject){
        setTimeout(function(){
            box[0].style.background ="#ddd";
            resolve();
        },1000)
    })
    var promise_box2 =promise_box1.then(function(){
        var promise_box2 =new Promise(function(resolve,reject){
            setTimeout(function(){
                box[1].style.background ="red";
                resolve();
            },1000)
        })
        return promise_box2;
    })
    var promise_box3 =promise_box2.then(function(){
        var promise_box3 =new Promise(function(resolve,reject){
            setTimeout(function(){
                box[2].style.background ="blue";
                resolve()
            },1000)
        })
        return promise_box3
    })
    var promise_box4 =promise_box3.then(function(){
        var promise_box4 =new Promise(function(resolve,reject){
            setTimeout(function(){
                box[3].style.background="green";
                resolve()
            },1000)
        })
    })
    promise_box4.then(function(){
        setTimeout(function(){
            box[4].style.background="black"
        },1000)
    })
</script>